package cn.iocoder.yudao.module.member.controller.admin.userfacelogs;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.member.controller.admin.userfacelogs.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.userfacelogs.UserFaceLogsDO;
import cn.iocoder.yudao.module.member.service.userfacelogs.UserFaceLogsService;

@Tag(name = "管理后台 - 用户面试日志")
@RestController
@RequestMapping("/member/user-face-logs")
@Validated
public class UserFaceLogsController {

    @Resource
    private UserFaceLogsService userFaceLogsService;

    @PostMapping("/create")
    @Operation(summary = "创建用户面试日志")
    @PreAuthorize("@ss.hasPermission('member:user-face-logs:create')")
    public CommonResult<Long> createUserFaceLogs(@Valid @RequestBody UserFaceLogsSaveReqVO createReqVO) {
        return success(userFaceLogsService.createUserFaceLogs(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户面试日志")
    @PreAuthorize("@ss.hasPermission('member:user-face-logs:update')")
    public CommonResult<Boolean> updateUserFaceLogs(@Valid @RequestBody UserFaceLogsSaveReqVO updateReqVO) {
        userFaceLogsService.updateUserFaceLogs(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户面试日志")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('member:user-face-logs:delete')")
    public CommonResult<Boolean> deleteUserFaceLogs(@RequestParam("id") Long id) {
        userFaceLogsService.deleteUserFaceLogs(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得用户面试日志")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('member:user-face-logs:query')")
    public CommonResult<UserFaceLogsRespVO> getUserFaceLogs(@RequestParam("id") Long id) {
        UserFaceLogsDO userFaceLogs = userFaceLogsService.getUserFaceLogs(id);
        return success(BeanUtils.toBean(userFaceLogs, UserFaceLogsRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得用户面试日志分页")
    @PreAuthorize("@ss.hasPermission('member:user-face-logs:query')")
    public CommonResult<PageResult<UserFaceLogsRespVO>> getUserFaceLogsPage(@Valid UserFaceLogsPageReqVO pageReqVO) {
        PageResult<UserFaceLogsDO> pageResult = userFaceLogsService.getUserFaceLogsPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, UserFaceLogsRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出用户面试日志 Excel")
    @PreAuthorize("@ss.hasPermission('member:user-face-logs:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportUserFaceLogsExcel(@Valid UserFaceLogsPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<UserFaceLogsDO> list = userFaceLogsService.getUserFaceLogsPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "用户面试日志.xls", "数据", UserFaceLogsRespVO.class,
                        BeanUtils.toBean(list, UserFaceLogsRespVO.class));
    }

}